<?php
/**
 * 公共模块库
一些公共的功能写入此，供其它模块调用
 * @author jroam
 *
 */
class commonAction extends Action{
	
	function top(){
		$hmoemr=A("Home/public");
		echo "dfdf";
		
	}
	/**
	 * 显示google地图
	 */
	function showgooglemap(){
		$zbz=$_REQUEST["zbz"];//google地图坐标值
		$hotelname=$_REQUEST["hname"];
		$widthpx=$_REQUEST["widthpx"];//地图宽度
		$heightpx=$_REQUEST["heightpx"];
		
		
		//验证坐标值格式
		if(getsubstr($zbz,"/^[\d\.]+,[\d\.]+$/")=="") die;
		if(!is_numeric($widthpx)) $widthpx=400;
		if(!is_numeric($heightpx))$heightpx=300;
		
		$this->assign("zbz",$zbz);
		$this->assign("hname",$hotelname);
		$this->assign("heightpx",$heightpx);
		$this->assign("widthpx",$widthpx);
		$this->display();
	}
	
	/**
	 * 实时获取每个房间的剩余房间数和价格等
	 * 
	 */
	function checkdateyoux(){
		$startdate=$_REQUEST["startdate"];//入住日期,由于url中的分隔符是-所以这里替换为_
		$enddate=$_REQUEST["enddate"];//离店日期  同上
		$hid=$_REQUEST["hid"];//客栈id
		$rid=$_REQUEST["rid"];//房间id
		$croomnum=$_REQUEST["n"];//选择的房间数量
		
		//检查并格式化时间
		if(getsubstr($startdate, "/^[\d]{4}_[\d]{1,2}_[\d]{1,2}$/")=="") die("入住时间格式错误");
		if(getsubstr($enddate, "/^[\d]{4}_[\d]{1,2}_[\d]{1,2}$/")=="") die("离店时间格式错误");
		if(!is_numeric($rid)) die("请从正确的地址进入");
		
		$startdate=str_replace("_", "-", $startdate);
		$enddate=str_replace("_", "-", $enddate);
		
			$numstart=strtotime($startdate);
			$numend=strtotime($enddate);
		$mr=M();
		//获取这个房间这段时间的批量值
		$sql="select * from ".DQ."price where price4=".$hid." and price3=612 and price13<=".$numstart." and price14>=".$numend."
			  and price19<>''
		";
		$rs=$mr->query($sql);
		
		$returnarr=array();//格式化后的数组
		
		if($rs){
			foreach ($rs as $v){
				$price19=$v["price19"];
				$p19arr=explode(",",$price19);
				foreach($p19arr as $v2){
					if(strstr($v2, "{id:$rid}")!=""){
						$returnarr["mzlj"]=getkuohaostr($v2, "/\{mzlj\:([\d\.]+)+\}/");//本站价
						$returnarr["tiqianyudin"]=getkuohaostr($v2, "/\{tiqianyudin\:([\d\.])+\}/");//提前预定天数
						$returnarr["zfbl"]=getkuohaostr($v2, "/\{zfbl\:([\d\.])+\}/");//定金支付比例
						$returnarr["kucunshu"]=getkuohaostr($v2, "/\{kucunshu\:([\d\.]+)\}/");//库存数
						
    					break;
					}
				}

			}
		}
		$temp=24*3600;
		
		//去获取单独设置的每一天的数据
		$sql="select hotelroom0,hotelroom12 from ".DQ."hotelroom where hotelroom0=".$rid;
		$rs=$mr->query($sql);
		
		for($i=$numend-$temp;$i>=$numstart;$i-=$temp){
			
			$tstr="". date("Y-m-d",$i)."    ,";
			if($croomnum>$returnarr["kucunshu"]){
				$tstr.="满房";
			}
			else {
				$tstr.="房价:".$returnarr["mzlj"]."元  * ".$croomnum."间";
				echo "{".$returnarr["mzlj"]*$croomnum."}";
			}
			$tstr.="<br>";
			echo $tstr;
		}
		
		//$this->display();
	}
	
	
	Public function verify(){
		import("ORG.Util.Image");
		Image::buildImageVerify();
	}
	

	
	
}

?>